<template>
  <div class="search-list">
    <div class="search-item" v-for="item in searchData" :key="item.id">
      <div class="clock">
        <van-icon name="clock-o" color="#ccc" size="18" />
      </div>
      <div class="history">
        {{ item.content }}
      </div>
      <div class="delete" @click="removeOne(item.id)">
        <van-icon name="cross" color="#ccc" size="18" />
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "SearchList",

  computed: {
    // 所有历史记录列表
    ...mapState(["searchData"]),
  },
  methods: {
    // 删除历史记录
    removeOne(id) {
      

      for (let i = 0; i < this.searchData.length; i++) {
        if (this.searchData[i].id === id) {
          this.$store
            .dispatch("removeHistory", i)
            .then(() => {})
            .catch((err) => {
              
            });
          break;
        }
      }
    },
  },
};
</script>

<style lang="less" scoped>
.search-list{
  display: none;
}
.search-item {
  height: 44px;
  background-color: #fff;
  display: flex;
  align-items: center;
  padding: 0 14px;
  position: relative;
  border-bottom: 1px solid #ddd;
  &:last-child{
    border-bottom: none;
  }
}
.history {
  font-size: 15px;
  color: #333;
  margin-left: 6px;
}
.delete {
  position: absolute;
  right: 14px;
}
</style>